package com.anysoft.ui.activity.web;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;

import com.anysoft.base.BaseWebViewActivity;
import com.anysoft.event.GestureEvent;
import com.anysoft.utils.ActivityCollector;
import com.anysoft.utils.HttpUtil;
import com.anysoft.utils.NetWorkUtil;
import com.anysoft.utils.StringUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;

/**
 * Created by LiTingYao on 2018/7/7.
 */
public class MentorZhiDaoEditActivity extends BaseWebViewActivity {
    
    private String params;
    private String id;
    
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String titleName = getIntent().getStringExtra("titleName");
        params = getIntent().getStringExtra("params");
        title.setText(StringUtil.isEmpty(titleName) ? "" : titleName);
        if (StringUtil.isEmpty(params)) {
            loadUrl = generateUrl("mentorZhiDaoEdit", HttpUtil.getCommonParams2StringByWeb(this));
        } else {
            loadUrl = generateUrl("mentorZhiDaoEdit", HttpUtil.getCommonParams2StringByWeb(this) + "&" + params);
        }
        if (NetWorkUtil.isConnect(this)) {
            setWebViewConfig(loadUrl);
        }
        
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        
    }
    
    @Override
    protected void onPause() {
        super.onPause();
    }
    
    @Override
    public void onshouldOverrideUrlLoadingCallBack(WebView webview, String url, String params) {
        HashMap<String, String> urlMap = handleUrlParams(url);
        String titleName = urlMap.get("title");
        id = urlMap.get("id");
        if (url.contains("mentorZhiDaoStudentSelect.html")) {
            mIntent.putExtra("titleName", titleName);
            mIntent.putExtra("params", params);
            ActivityCollector.startTargetActivity(this, MentorZhiDaoStudentSelectActivity.class, mIntent);
        } else {
            mIntent.putExtra("url", url);
            ActivityCollector.startTargetActivity(this, SecondCommActivity.class, mIntent);
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGestureCallBack(GestureEvent event) {
        if (event.isSuccess) {
            loadUrl = generateUrl("mentorZhiDaoEdit", HttpUtil.getCommonParams2StringByWeb(this) + "&" + replaceUrlParams("id", id, params));
            reLoadPage(loadUrl);
        }
    }
}
